package com.bynk.bynk_demo.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CorsConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        //允许跨域的路径
        CorsRegistration corsRegistration = registry.addMapping("http://localhost:8080")
                //允许的跨域访问源
                .allowedOrigins("*")
                //允许的请求方法
                .allowedMethods("POST", "GET", "DELETE", "OPTIONS")
                //允许的请求头
                .allowedHeaders("*")
                //是否允许cookie
                .allowCredentials(true)
                //预检查间隔时间
                .maxAge(16800);
    }
}
